package com.as.measurements.client.core;

import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.service.component.ComponentContext;

import com.as.measurements.client.listener.MeasurementsListener;
import com.as.measurements.client.service.QoSParamsService;

public class QoSimpl implements QoSParamsService {

	/**
	 * Logger
	 */
	private Log _logger = LogFactory.getLog(getClass().getName());
	
	 MeasurementsListener _listener;

	public void QoSimpl() {

		// TODO

	}

	@Override
	public void getQoSParams(Properties net) {
		// TODO Auto-generated method stub
		
		/*
		 * the properties will have the following format
		 * IPERF_POR IFACE_IP xxx.xxx.xxx.xxx 
		 * IFACE_NAME xx 
		 * ERVER_IP  xxx.xxx.xxx.xxx
		 */
		// TODO comando a pincho ? al menos leer de un properties
		
		//iperf -c 192.168.3.16 -u -i 1 -p 5001 -f k -b 100.0M -t 5 -T 1 -r
		String command = "iperf -c " + net.getProperty("SERVER_IP")
				+ " -u -i 1 -p " + net.getProperty("IPERF_PORT")
				+ " -B " + net.getProperty("IFACE_IP") + " -f m -b 100.0M -t 5"; // TODO

		_logger.debug(" system call: " + command);
		// se manda el interface de la medida ... de momento a piñon
		QoSAgent qos = new QoSAgent(false, command, _listener, net.getProperty("IFACE_NAME"));
		qos.run();
	}

	protected void activate(ComponentContext context) {
		_logger.info("Activated component:" + getClass().getName());

	}

	protected void deactivate(ComponentContext context) {
		_logger.info("Desactivate component:" + getClass().getName());

	}

	@Override
	public void addListener(MeasurementsListener listener) {
		// TODO Auto-generated method stub
		_listener = listener;
		
	}



}
